<?php

namespace app\admin\controller\user;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Db;

/**
 * @ControllerAnnotation(title="user_feedback")
 */
class Feedback extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\UserFeedback();
        
    }

     /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $count = $this->model
                ->where($where)
                ->count();
            $list = $this->model
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select();
                foreach ($list as $k => $v){
                    //用户
                    if(!empty($v['uid'])){
                        $user = Db::name('user')->where('id',$v['uid'])->find();
                        $v['nickname'] = $user['nickname'];
                        $v['phone'] = $user['phone'];
                        $v['avatar'] = $user['avatar'];
                    }else{
                        $v['nickname'] = "";
                        $v['phone'] = "";
                        $v['avatar'] = "";
                    }
                    
                    $list[$k] = $v;
                }
          
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }


        /**
    * @NodeAnotation(title="查看详情")
    */
    public function edit()
    {
        $post = $this->request->param(); 
        $row = $this->model->where('id',$post['id'])->find();
        $row["imgArr"] = explode("|",$row["img"]);
        $this->assign('row', $row); 
        return $this->fetch();
       
    }
 
    
}